<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

/**
 * 客户端入口
 */
//>>>>>>>>>>>>>>>>>>>>>>>>start

/**
 * 默认路由，返回主页
 */
Route::get('/', function()
{
	return View::make('product');
});


/**
 * 验证模块路由
 */
Route::get('/authority', 'AuthorityController@getLogin');
Route::controller('authority', 'AuthorityController');

/**
 * 商品模块
 */
Route::get('/product', function(){
    return View::make('product');
});

//暂时应用的order，该路由英港你改一改
Route::get('/order', function(){
    return View::make('order');
});

//暂时应用的administrator,该路由英港你改一改
Route::get('/administrator', function(){
  return View::make('administrator');
});


/**
 * 用于需要验证账户信息的路由组
 */
Route::group(array('before' => 'auth'), function(){
    /**
     * 个人主页模块
     */
    Route::get('/personal', function(){
        return View::make('personal');
    });

    /**
     * 购物车模块
     */
    Route::get('/cart', function(){
        return View::make('cart');
    });

    /**
     * 订单模块
     */
    Route::get('/order', function(){
       return View::make('order');
    });

});
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

/**
 * angular api 入口
 */
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>开始
Route::group(['prefix' => 'api'], function(){
    /**
     * 商品模块
     */
    Route::resource('product', 'ProductController',
        ['only' => ['index', 'show', 'store', 'update', 'destroy']]);

    /**
     * 辅助功能,三级联动地区获取
     */
    Route::get('district', function(){
        return Response::json(Linkage::where('type', 1)->get()->toArray());
    });

    Route::get('district/{province_id}', function($province_id){
        return Response::json(Linkage::where('sup_id', $province_id)->where('type', 2)->get()->toArray());
    });

    Route::get('district/{province_id}/{city_id}', function($province_id, $city_id){
        return Response::json(Linkage::where('sup_id', $city_id)->where('type', 3)->get()->toArray());
    });


    /**
     * 用于需要验证账户信息的路由组
     */
    Route::group(array('before' => 'auth'), function()
    {
        /**
         * 个人主页模块
         */

        //个人基本信息
        Route::get('personal/baseinfo', 'BaseInfoController@getBaseInfo');
        Route::put('personal/baseinfo', 'BaseInfoController@putBaseInfo');

        //个人收货地址
        Route::resource('personal/address', 'AddressController',
            ['only' => ['index', 'show', 'update', 'store', 'destroy']]);

        /**
         * 购物车模块
         */
        Route::resource('/cart', 'CartController',
            ['only' => ['index', 'update', 'destroy', 'store']]);

        /**
         * 订单模块
         */
        Route::resource('/order', 'OrderController',
            ['only' => ['index', 'update', 'destroy', 'store', 'show']]);

    });
});
//<<<<<<<<<<<<<<<<结束

/**
 * cookie 测试
 */
Route::get('/cookieCart', function(){
    return Cookie::get('cookieCart');
});

Route::get('cookieProduct', 'CartController@index');

///**
// * 地区获取测试
// */
//
//Route::get('/api/district', function(){
//    return Response::json(Linkage::where('type', 1)->get()->toArray());
//});
//
//Route::get('/api/district/{province_id}', function($province_id){
//    return Response::json(Linkage::where('sup_id', $province_id)->get()->toArray());
//});
//
//Route::get('api/district/{province_id}/{city_id}', function($province_id, $city_id){
//    return Response::json(Linkage::where('sup_id', $city_id)->get()->toArray());
//});